//
//  Preferens.m
//  HappyStore
//
//  Created by 李小辉 on 16/6/14.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "Preferens.h"

@interface Preferens ()
@property (weak, nonatomic) IBOutlet UIButton *industryBtn;//行业方向
@property (weak, nonatomic) IBOutlet UILabel *industryLabel;
@property (weak, nonatomic) IBOutlet UIButton *skillLabelBtn;//技能标签
@property (weak, nonatomic) IBOutlet UILabel *skillLabel;
@property (weak, nonatomic) IBOutlet UIButton *cityBtn;//工作地区城市
@property (weak, nonatomic) IBOutlet UILabel *cityLabel;
@property (weak, nonatomic) IBOutlet UIButton *payrollBtn;//期望薪资
@property (weak, nonatomic) IBOutlet UILabel *payrollLabel;
@property (weak, nonatomic) IBOutlet UIButton *experienceBtn;//工作经验
@property (weak, nonatomic) IBOutlet UILabel *experienceLabel;
@property (weak, nonatomic) IBOutlet UIButton *natureWorkBtn;//工作性质
@property (weak, nonatomic) IBOutlet UILabel *natureWorkLabel;

//行业
@property (strong, nonatomic) NSArray *aryHYtitle;//数据
//薪资
@property (strong, nonatomic) NSArray *payrollAry;
//工作经验
@property (strong, nonatomic) NSArray *experienceAry;
//工作性质
@property (strong, nonatomic) NSArray *natureWorkAry;
//地区
@property (strong, nonatomic) NSString *provinceStr;
@property (strong, nonatomic) NSString *cityStr;
@property (strong, nonatomic) NSString *districtStr;




@property (strong, nonatomic) SelectedAddress *selectAddress;
@property (strong, nonatomic) SingleSelectedDialog *tableViewIndustry;

@end


@implementation Preferens

- (NSArray *)payrollAry{
    if (!_payrollAry) {
        _payrollAry = @[@"3K以下",@"3K-5K",@"5K-10K",@"10K以上"];
    }
    return _payrollAry;
}
- (NSArray *)natureWorkAry{
    if (!_natureWorkAry) {
        _natureWorkAry = @[@"不限",@"实习",@"全职",@"兼职"];
    }
    return _natureWorkAry;
}
- (NSArray *)experienceAry{
    if (!_experienceAry) {
        _experienceAry = @[@"一年以下",@"1-3年",@"3-5年",@"5-10年",@"10年以上",@"不限"];
    }
    return _experienceAry;
}
- (NSArray *)aryHYtitle{
    if (!_aryHYtitle) {
        _aryHYtitle = @[@"生物医药",@"旅游休闲",@"制造业",@"批发零售",
                        @"房地产业",@"交通运输",@"冶金矿业",@"建筑建材",
                        @"信息软件",@"金融",@"教育",@"现代服务业",
                        @"生态环保",@"市政基建",@"文体娱乐",@"社会保障"
                        ,@"水电燃气",@"农林牧渔",@"其他行业"];
    }
    return _aryHYtitle;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设置职位偏好";
    UIBarButtonItem *rightBar = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(rightButtonItemClick)];
    self.navigationItem.rightBarButtonItem = rightBar;
    
    
    self.tableViewIndustry = [SingleSelectedDialog sharedSelectedAddress];
    self.tableViewIndustry.delegatee = self;
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}

- (void)rightButtonItemClick{
    
    //page=页码&type=（1招聘 2求职）&title=根据名称&industry=根据行业&money=-根据金额，格式（0-5000000 亿以上：1000000000-亿）&address= 根据地区（格式：省-市-区 如果没有就：省-无-无）&experience=年限（1>一年以下 2>1-3年 3>3-5年 4>5-10年 5>10年以上 6>不限）
    NSMutableDictionary *dicInfo = [NSMutableDictionary dictionary];
    [dicInfo setObject:@"1" forKey:@"page"];
    if (self.industryLabel.text.length != 0) {//根据行业
        [dicInfo setObject:self.industryLabel.text forKey:@"industry"];
    }
    if (self.payrollLabel.text.length != 0) {//根据金额
        if ([self.payrollLabel.text isEqualToString:@"3K以下"]) {
            [dicInfo setObject:@"0-3000" forKey:@"money"];
        }else if ([self.payrollLabel.text isEqualToString:@"3K-5K"]){
            [dicInfo setObject:@"3000-5000" forKey:@"money"];
        }else if ([self.payrollLabel.text isEqualToString:@"5K-10K"]){
            [dicInfo setObject:@"5000-10000" forKey:@"money"];
        }else if ([self.payrollLabel.text isEqualToString:@"10K以上"]){
            [dicInfo setObject:@"10000-900000000" forKey:@"money"];
        }
        
    }
    
    
    if (self.experienceLabel.text.length != 0) {//经验&experience=年限（1>一年以下 2>1-3年 3>3-5年 4>5-10年 5>10年以上 6>不限）
        [dicInfo setObject:self.experienceLabel.text forKey:@"experience"];
    }

    if (self.cityLabel.text.length != 0) {//根据地区
        [dicInfo setObject:[NSString stringWithFormat:@"%@-%@-%@",self.provinceStr, self.cityStr, self.districtStr] forKey:@"address"];
    }
    if (self.natureWorkLabel.text.length !=0) {
        [dicInfo setObject:self.natureWorkLabel.text forKey:@"workNature"];
    }
    
    [dicInfo setObject:@(1) forKey:@"type"];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"StartShaiXuanRecruitment" object:nil userInfo:dicInfo];
    
    [self.navigationController popViewControllerAnimated:YES];
}







#pragma mark - 选择行业
- (IBAction)industryBtnClick:(UIButton *)sender {
    self.industryBtn.selected = YES;
    NSMutableArray *muAry = [NSMutableArray array];
    for (int i=0; i<self.aryHYtitle.count; i++) {
        [muAry addObject:self.aryHYtitle[i]];
    }
    [self.tableViewIndustry btnClickAddressWithData:muAry];
 
}

#pragma mark -选择技能标签
- (IBAction)skillLabelBtnClick:(UIButton *)sender {
}
#pragma mark - 选择地区
- (IBAction)cityBtnClick:(UIButton *)sender {
    self.selectAddress = [SelectedAddress sharedSelectedAddress];
    self.selectAddress.delegatee = self;
    [self.selectAddress btnClickAddress];
}
//实现协议方法
- (void)seceltedRowSshowMsg:(NSString *)showMsg andProvince:(NSString *)strProvince andCity:(NSString *)strCity andDistrict:(NSString *)strDistrict{
    self.provinceStr = strProvince;
    self.cityStr = strCity;
    self.districtStr = strDistrict;
    
    self.cityLabel.text = [NSString stringWithFormat:@"%@/%@/%@",self.provinceStr,self.cityStr,self.districtStr];
}

#pragma mark - 薪资
- (IBAction)payrollBtnClick:(UIButton *)sender {
    self.payrollBtn.selected = YES;
    NSMutableArray *muAry = [NSMutableArray array];
    for (int i=0; i<self.payrollAry.count; i++) {
        [muAry addObject:self.payrollAry[i]];
    }
    [self.tableViewIndustry btnClickAddressWithData:muAry];
}
#pragma mark - 选择工作年限
- (IBAction)experienceBtnClick:(UIButton *)sender {
    self.experienceBtn.selected = YES;
    
    NSMutableArray *muAry = [NSMutableArray array];
    for (int i=0; i<self.experienceAry.count; i++) {
        [muAry addObject:self.experienceAry[i]];
    }
    [self.tableViewIndustry btnClickAddressWithData:muAry];
}
//工作性质
- (IBAction)natureWorkBtnClick:(UIButton *)sender {
    self.natureWorkBtn.selected = YES;
    NSMutableArray *muAry = [NSMutableArray array];
    for (int i=0; i<self.natureWorkAry.count; i++) {
        [muAry addObject:self.natureWorkAry[i]];
    }
    [self.tableViewIndustry btnClickAddressWithData:muAry];
}




//方法
- (void)seceltedRow:(NSInteger)rrow{
    
    if (self.industryBtn.selected) {
        self.industryLabel.text = self.aryHYtitle[rrow];
        self.industryBtn.selected = NO;
    }
    if (self.experienceBtn.selected) {
         self.experienceLabel.text = self.experienceAry[rrow];
        self.experienceBtn.selected = NO;
    }
    if (self.natureWorkBtn.selected) {
        self.natureWorkLabel.text = self.natureWorkAry[rrow];
        self.natureWorkBtn.selected = NO;
    }
    if (self.payrollBtn.selected) {
        self.payrollLabel.text = self.payrollAry[rrow];
        self.payrollBtn.selected = NO;
    }
   
}
@end
